home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15722 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1019 b 

  1. Path: ix.netcom.com!news
  2. From: philma@ix.netcom.com(Phil Majtan)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What is wrong with this loop?
  5. Date: 20 Apr 1996 22:27:41 GMT
  6. Organization: Netcom
  7. Message-ID: <4lboct$nni@dfw-ixnews3.ix.netcom.com>
  8. References: <4l86la$1t9@uwm.edu>
  9. NNTP-Posting-Host: det-mi4-10.ix.netcom.com
  10. X-NETCOM-Date: Sat Apr 20  5:27:41 PM CDT 1996
  11.  
  12. In <4l86la$1t9@uwm.edu> mardavuy@alpha2.csd.uwm.edu (Mario David Uy)
  13. writes: 
  14. >
  15. >#include <stdio.h>
  16. >int main(void)
  17. >{
  18. >   int dia;
  19. >
  20. >   char cd;
  21. >
  22. >   ...
  23. >
  24. >   scanf("%c", &cd);
  25. >   while (cd != 'm' || cd ! 'f' || cd != 'o')
  26. >    {
  27. >    printf("Re-enter m, f, or o.\n");
  28. >    scanf(%c", &cd);
  29. >    }
  30. >   ...
  31. >}
  32. >
  33. >It works fine, except that it gives me the printf() twice.
  34. >
  35.  
  36. I think you might need to re-examine the logic.  As far as I remember
  37. in logic class, having three negative or's like that will always be
  38. true.  What you probably need is  !=g && !=f && !=o  or something like
  39. that, because they ALL have to be true to not ask for input again.  You
  40. see?
  41. Phil
  42.  
  43.